#ifndef __PROTOCOL_ANALYSIS_H__
#define __PROTOCOL_ANALYSIS_H__

#include "stdint.h"
#include "app_clock.h"
#include "ble_lbs_c.h"

#define MAX_BLE_SEND_DATA_LEN       20
#define MAX_BLE_RCV_DATA_LEN        20

#define FIRMWARE_OTA_CMD            0x01
#define GET_PARA_CMD                0x02
#define SET_PARA_CMD                0x03
#define BOND_DEVICE_CMD             0x04
#define CONTROL_DEVICE_CMD          0x05
#define DEVICE_RESET_CMD            0x06


#define SET_TIME_KEY                0x01

#define CONTROL_OPEN_KEY            0x01
#define CONTROL_CLOSE_KEY           0x02
#define CONTROL_STOP_KEY            0x03
#define CONTROL_TURNONLAMP_KEY      0x04
#define CONTROL_TURNOFFLAMP_KEY     0x05

typedef struct
{
    uint8_t cmd:8;
    uint8_t key:8;
    uint8_t year_low:8;
    uint8_t year_heigh:8;
    uint8_t month:8;
    uint8_t day:8;
    uint8_t hour:8;
    uint8_t minute:8;
    uint8_t second:8;
    uint8_t week_day:8;
    uint8_t reserved0:8;
    uint8_t reserved1:8;
    uint8_t reserved2:8;
    uint8_t reserved3:8;
    uint8_t reserved4:8;
    uint8_t reserved5:8;
    uint8_t reserved6:8;
    uint8_t reserved7:8;
    uint8_t reserved8:8;
    uint8_t reserved9:8;
}time_protocal_t;

typedef struct
{
    uint8_t cmd:8;
    uint8_t key:8;
    uint8_t percent:8;
    uint8_t reserved0:8;
    uint8_t reserved1:8;
    uint8_t reserved2:8;
    uint8_t reserved3:8;
    uint8_t reserved4:8;
    uint8_t reserved5:8;
    uint8_t reserved6:8;
    uint8_t reserved7:8;
    uint8_t reserved8:8;
    uint8_t reserved9:8;
    uint8_t reserved10:8;
    uint8_t reserved11:8;
    uint8_t reserved12:8;
    uint8_t reserved13:8;
    uint8_t reserved14:8;
    uint8_t reserved15:8;
    uint8_t reserved16:8;
}control_protocal_t;

typedef union
{
    uint8_t         tx_buff[MAX_BLE_SEND_DATA_LEN];
    time_protocal_t time;
}tx_time_t;

typedef union
{
    uint8_t         tx_buff[MAX_BLE_SEND_DATA_LEN];
    //time_protocal_t time;
}ota_cmd_t;

typedef union
{
    uint8_t         tx_buff[MAX_BLE_SEND_DATA_LEN];
    control_protocal_t control;
}tx_control_t;


/* 发送设置从机时间的命令 */
void Set_Time_Command_Tx(clock_time_t* time);

/* 发送控制开窗户命令 */
void Open_Curtain_Command_Tx(uint8_t percent);

/* 发送控制关窗户命令 */
void Close_Curtain_Command_Tx(uint8_t percent);

/* 发送控制停止窗帘运动命令 */
void Stop_Curtain_Command_Tx(uint8_t percent);

/* 发送控制打开台灯命令 */
void TurnOnLamp_Command_Tx(uint8_t percent);

/* 发送控制关闭台灯命令 */
void TurnOffLamp_Command_Tx(uint8_t percent);

/* 发送进入DFU模式命令 */
void Enter_Dfu_Mode(void);

#endif //__PROTOCOL_ANALYSIS_H__
